package org.zjt.book

/**
  * DESC    辅助构造函数测试
  *
  * @author
  * @create 2017-04-26 上午9:52
  **/
class Person {

  var name :String = null

  var age : Int = 0

  def this(name :String){
    this()
    this.name = name
  }


  def this(name :String ,age :Int ){
    this(name)
    this.age =age
  }

  def descript = this.name + " : " +this.age

}


/**
  * 构造函数
  * PS: 默认包含属性、属性get、属性set
  * @param name
  * @param age
  */
class Person2(var name:String ,var age :Int){

  println("构造对象时候，执行所有的语句，非方法")
  def descript = this.name + " : " +this.age

}


object start{
  def main(args: Array[String]): Unit = {

    var p = new Person();
    println(p.descript)
    p.age = 18
    p.name = "zhang"
    println(p.descript)


    p = new Person("zhang")
    println(p.descript)


    p = new Person(name ="zhang",age =24)
    println(p.descript)


    var p1 = new Person2("zhang",133)
    println(p.descript)
  }
}